package config;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;


@Configuration
public class CaffeineConfig {

    @Bean
    public Cache<String, Boolean> caffeineCache(){
        return Caffeine.newBuilder()
                //这只最后一次写入或访问后的过期时间
                .expireAfterWrite(5, TimeUnit.SECONDS)
                //初始化缓存的大小
                .initialCapacity(20)
                //设置缓存的最大容量
                .maximumSize(500)
                .build();
    }
}
